/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-09-29 08:39:39
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-10-18 09:12:23
 * @FilePath: /react18-vite-admin/src/views/system/DeptManage/DeptManage.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Form, Table } from 'antd';

import CustomCard from '@/components/ui/CustomCard/CustomCard';
import Button from '@/components/ui/Button/Button';
import type { DeptTreeItem } from '@/typings/api/department';

import { useTable } from './useTable';
import EditView from './components/EditView';
import { useEffect } from 'react';

const UsersManage = () => {
    const { handleEdit, columns, tree, loading, editNsp, setEditNsp, afterUpdate } =
        useTable();

    useEffect(() => {
        console.log('部门管理渲染');
    }, []);

    return (
        <div className="page-container">
            <CustomCard title="">
                <Form className="filter-form mb" layout="inline">
                    <Form.Item>
                        <Button type="success" onClick={() => handleEdit()}>
                            新增
                        </Button>
                    </Form.Item>
                </Form>

                <Table<DeptTreeItem>
                    columns={columns}
                    dataSource={tree}
                    rowKey={(record) => record.id}
                    loading={loading}
                ></Table>
            </CustomCard>

            <EditView
                open={editNsp.open}
                detail={editNsp.detail}
                parentId={editNsp.parentId}
                onClose={() =>
                    setEditNsp((draft) => {
                        draft.open = false;
                    })
                }
                afterSubmit={afterUpdate}
            />
        </div>
    );
};

export default UsersManage;
